package org.truxingame.input;

import org.truxingame.Vector2;

public class GamePadState {
	GamePadButtons buttons;
	GamePadDPad dpad;
	GamePadTriggers triggers;
	GamePadThumbSticks thumbsticks;
	boolean connected = true;
	public long packet;
	
	GamePadState(
				GamePadButtons _buttons,
				GamePadDPad _dpad,
				GamePadTriggers _triggers,
				GamePadThumbSticks _thumbsticks) {
		buttons = _buttons;
		dpad = _dpad;
		triggers = _triggers;
		thumbsticks= _thumbsticks;
	}
	
	
	public int getPacketNumber () {
		return (int)packet;
	}
	
	public GamePadButtons getButtons() {
		return buttons;
	}
	public GamePadDPad getDPad() {
		return dpad;
	}
	
	public GamePadTriggers getTriggers() {
		return triggers;
	}
	
	public GamePadThumbSticks getThumbsticks() {
		return thumbsticks;
	}
	
	public boolean isConnected() {
		return connected;
	}
	
	public boolean isButtonDown(Buttons b) {
		if ((buttons.buttons.flags & b.flags) == b.flags)
			return true;
		return false;
	}

	public boolean isButtonUp(Buttons b) {
		if ((buttons.buttons.flags & b.flags) == 0)
			return true;
		return false;
	}

	static GamePadState disconnected;
	static {
		final Buttons none = new Buttons (0);
		final Vector2 zero = new Vector2(0,0);
		disconnected = new GamePadState(
				new GamePadButtons(none), 
				new GamePadDPad(none), 
				new GamePadTriggers(0, 0), 
				new GamePadThumbSticks(zero, zero));
		disconnected.connected = false;

	}
	
	public static GamePadState getDisconnected() {
		
		return disconnected;
	}
}
